<template>
  <a-layout class="basic-layout">
    <!-- 顶部导航栏 -->
    <GlobalHeader v-if="route.meta.showHeader===true"/>
    
    <!-- 主要内容区域 -->
    <a-layout-content class="main-content" :class="{ 'content-margin': shouldAddMargin }">
      <RouterView />
    </a-layout-content>
    
    <!-- 底部版权信息 -->
    <GlobalFooter v-if="route.meta.showFooter===true"/>
  </a-layout>
</template>

<script setup lang="ts">
import { RouterView, useRoute } from 'vue-router'
import GlobalHeader from '@/components/GlobalHeader.vue'
import GlobalFooter from '@/components/GlobalFooter.vue'
import { computed } from 'vue';

/**
 * 使用 route 读取 route.meta，并用 v-if 控制头部和底部的渲染
 * 1.登录页面和注册页面不需要显示头部和底部
 */
const route = useRoute();

// 计算属性判断是否需要添加 margin
const shouldAddMargin = computed(() => {
  return route.meta.showHeader === true || route.meta.showFooter === true;
});

</script>

<style scoped>
.basic-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255);
}

/* 动态添加的 margin */
.content-margin {
  margin-top: 64px;
}
</style>